//
//  OpenCellButtonView.m
//  Gunterapple
//
//  Created by 热带雨林 on 2021/2/3.
//  Copyright © 2021 热带雨林. All rights reserved.
//

#import "OpenCellButtonView.h"

//使用静态函数创建按钮
static GDButton * creatGDButton(NSString *title,CGFloat fontSize,NSString *imageName,CGFloat width,CGFloat height,CGFloat x,CGFloat y){
    
    UIFont *font = [UIFont systemFontOfSize:fontSize];
    CGRect rect = [title boundingRectWithSize:CGSizeMake(MAXFLOAT, 30) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : font}  context:nil];
    GDButton *defaultBtn = [[GDButton alloc]initWithFrame:CGRectMake(0, 0, rect.size.width + width + 5 , height + 20)];
    [defaultBtn setTitle:title forState:UIControlStateNormal];
    [defaultBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [defaultBtn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    defaultBtn.imageRect = CGRectMake(x, 0, width, height);
    defaultBtn.titleRect = CGRectMake(width + 10, y, rect.size.width, fontSize);
    return defaultBtn;
    
}

@interface OpenCellButtonView ()

@property (nonatomic, strong) GDButton *likeBtn;
@property (nonatomic, strong) GDButton *commentBtn;
@property (nonatomic, strong) GDButton *camereBtn;

@end
@implementation OpenCellButtonView

- (instancetype)initWithFrame:(CGRect)frame{
    if(self = [super initWithFrame:frame]){
        [self setUpUI];
    }
    return self;
}

- (void)setUpUI{
    
    self.likeBtn = creatGDButton(@"like", 13, @"like", 20, 20, 5, 2);
    self.likeBtn.tag = GDButtonLike;
    self.camereBtn = creatGDButton(@"camera", 13, @"tl_home_camera_publish", 20, 20, 5, 2);
    self.camereBtn.tag = GDButtonCareme;
    self.commentBtn = creatGDButton(@"comment", 13, @"comment", 20, 20, 5, 2);
    self.commentBtn.tag = GDButtonComment;
    
    [self creatGDButtonWithArray:@[self.likeBtn,self.camereBtn,self.commentBtn]];
    
}

//在分类中已有的方法  不需要使用代理
-(void)clickButtonAction:(UIButton *)sender{
    switch (sender.tag) {
        case 0:{
            NSLog(@"this is like");
            break;
        }
        case 1:{
            NSLog(@"this is comment");
            break;
        }
        case 2:{
            NSLog(@"this is caremete");
            break;
        }
        default:
            break;
    }
}






@end
